<?php
    include('header.php');
    include('sidebar2.php');
    
    $seccode = $_GET['code'];
    $mem_info = $db->queryUniqueObject("SELECT m_id , m_name , m_lastname , m_email FROM hs_member WHERE m_seccode LIKE '$seccode'");
    
    if($mem_info->m_name!=NULL){
        $password = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789'),0,5);
        
        $msg = $status_msg['regis_success'];
        
        $file = APPPATH.'/mail/member_register_success.txt';
        $handle = fopen($file,'r');
        //$body = fgets($handle);
        $body = '';
        if ($handle) {
            while (!feof($handle)) {
                $file_ = fgets($handle, 4096);
                $body .= $file_."<br>";
            }
            fclose($handle);
        }
        
        $mail = new PHPMailer();
        $mail->IsMail();
        $mail->CharSet="utf-8";
        $mail->IsHTML(true);
        $mail->From = MAIN_EMAIL;
        
        $body = str_replace('{NAME}',$mem_info->m_name,$body);
        $body = str_replace('{LASTNAME}',$mem_info->m_lastname,$body);
        $body = str_replace('{SITENAME}',SITENAME,$body);
        $body = str_replace('{PASSWORD}',$password,$body);
        
        $mail->FromName = REGIS_SUCCESS_TITLE;
        $mail->AddReplyTo(MAIN_EMAIL, REGIS_SUCCESS_TITLE);
        $mail->AddAddress($mem_info->m_email);
        $mail->Subject = REGIS_SUCCESS_TITLE;
        $mail->Body = $body;
        $mail->Send();
        
        $time_ = time();
        $result = $db->query("UPDATE hs_member SET m_seccode='' , m_update =$time_ , m_confirm=1 WHERE m_id=".$mem_info->m_id);
    }else{
        $msg = $status_msg['invalid_code'];
    }
?>
            <div id="main_content" class="register_content">
                <img src="images/register_title.jpg" alt="Order" id="register_title" />
                
                <div id="success_msg">
                <?php echo $msg; ?>
                </div>
            </div>
            <div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>